home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / KRIEG.ICN < prev    next >
Text File  |  1993-01-27  |  38KB  |  1,215 lines

  1. ############################################################################
  2. #
  3. #    File:     krieg.icn
  4. #
  5. #    Subject:  Program to play kriegspiel
  6. #
  7. #    Author:   David J. Slate
  8. #
  9. #    Date:     July 25, 1989
  10. #
  11. ###########################################################################
  12. #
  13. #   The game:
  14. #   
  15. #   Kriegspiel (German for "war game") implements a monitor and, if desired,
  16. #   an automatic opponent for a variation of the game of chess which has the
  17. #   same rules and goal as ordinary chess except that neither player sees
  18. #   the other's moves or pieces.  Thus Kriegspiel combines the intricacies
  19. #   and flavor of chess with additional elements of uncertainty, psychology,
  20. #   subterfuge, etc., which characterize games of imperfect information such
  21. #   as bridge or poker.
  22. #   
  23. #   The version of the game implemented here was learned by the author
  24. #   informally many years ago.  There may be other variations, and perhaps
  25. #   the rules are actually written down somewhere in some book of games.
  26. #   
  27. #   The game is usually played in a room with three chess boards set up on
  28. #   separate tables.  The players sit at the two end tables facing away from
  29. #   each other.  A third participant, the "monitor", acts as a referee and
  30. #   scorekeeper and keeps track of the actual game on the middle board,
  31. #   which is also out of sight of either player.  Since each player knows
  32. #   only his own moves, he can only guess the position of the enemy pieces,
  33. #   so he may place and move these pieces on his board wherever he likes.
  34. #   
  35. #   To start the game, the "White" player makes a move on his board.  If the
  36. #   move is legal, the monitor plays it on his board and invites "Black" to
  37. #   make his response.  If a move attempt is illegal (because it leaves the
  38. #   king in check or tries to move through an enemy piece, etc.), the
  39. #   monitor announces that fact to both players and the moving player must
  40. #   try again until he finds a legal move.  Thus the game continues until it
  41. #   ends by checkmate, draw, or agreement by the players.  Usually the
  42. #   monitor keeps a record of the moves so that the players can play the
  43. #   game over at its conclusion and see what actually happened, which is
  44. #   often quite amusing.
  45. #   
  46. #   With no additional information provided by the monitor, the game is very
  47. #   difficult but, surprisingly, still playable, with viable tactical and
  48. #   strategic ideas.  Usually, however, the monitor gives some minimal
  49. #   feedback to both players about certain events.  The locations of
  50. #   captures are announced as well as the directions from which checks on
  51. #   the kings originate.
  52. #   
  53. #   Even with the feedback about checks and captures, a newcomer to
  54. #   Kriegspiel might still think that the players have so little information
  55. #   that they could do little more than shuffle around randomly hoping to
  56. #   accidentally capture enemy pieces or checkmate the enemy king.  But in
  57. #   fact a skilled player can infer a lot about his opponent's position and
  58. #   put together plans with a good chance of success.  Once he achieves a
  59. #   substantial material and positional advantage, with proper technique he
  60. #   can usually exploit it by mopping up the enemy pieces, promoting pawns,
  61. #   and finally checkmating the enemy king as he would in an ordinary chess
  62. #   game.  In the author's experience, a skilled Kriegspiel player will win
  63. #   most games against a novice, even if both players are equally matched at
  64. #   regular chess.
  65. #   
  66. #   The implementation:
  67. #   
  68. #   The functions of this program are to replace the human monitor, whose
  69. #   job is actually fairly difficult to do without mistakes, to permit the
  70. #   players to play from widely separate locations, to produce a machine-
  71. #   readable record of the game, and to provide, if desired, a computer
  72. #   opponent for a single player to practice and spar with.
  73. #   
  74. #   When two humans play, each logs in to the same computer from a separate
  75. #   terminal and executes his own copy of the program.  This requires a
  76. #   multi-tasking, multi-user operating system.  For various reasons, the
  77. #   author chose to implement Kriegspiel under UNIX, using named pipes for
  78. #   inter-process communication.  The program has been tested successfully
  79. #   under Icon Version 7.5 on a DecStation 3100 running Ultrix (a Berkeley-
  80. #   style UNIX) and also under Icon Version 7.0 on the ATT UNIX-PC and
  81. #   another System V machine, but unanticipated problems could be
  82. #   encountered by the installer on other computers.  An ambitious user may
  83. #   be able to port the program to non-UNIX systems such as Vax-VMS.  It may
  84. #   also be possible to implement Kriegspiel on a non-multi-tasking system
  85. #   such as MS-DOS by using separate computers linked via serial port or
  86. #   other network.  See the "init" procedure for much of the system-
  87. #   dependent code for getting user name, setting up communication files,
  88. #   etc.
  89. #   
  90. #   Two prospective opponents should agree on who is to play "white", make
  91. #   sure they know each other's names, and then execute Kriegspiel from
  92. #   their respective terminals.  The program will prompt each player for his
  93. #   name (which defaults to his user or login name), his piece color, the
  94. #   name of his opponent, whether he wishes to play in "totally blind" mode
  95. #   (no capture or check information - not recommended for beginners), and
  96. #   the name of the log file on which the program will leave a record of the
  97. #   game (the program supplies a default in /tmp).  Each program will set up
  98. #   some communication files and wait for the opponent's to show up.  Once
  99. #   communication is established, each player will be prompted for moves and
  100. #   given information as appropriate.  The online "help" facility documents
  101. #   various additional commands and responses.
  102. #   
  103. #   A player who wants a computer opponent should select "auto" as his
  104. #   opponent's name.  Play then proceeds as with a human opponent.  "Auto"
  105. #   is currently not very strong, but probably requires more than novice
  106. #   skill to defeat.
  107. #
  108. #   Known bugs and limitations:
  109. #
  110. #   No bugs are currently known in the areas of legal move generation,
  111. #   board position updating, checkmate detection, etc., but it is still
  112. #   possible that there are a few.
  113. #
  114. #   Some cases of insufficient checkmating material on both sides are
  115. #   not detected as draws by the program.
  116. #
  117. #   In the current implementation, a player may not play two
  118. #   simultaneous games under the same user name with the same piece color.
  119. #
  120. #   If the program is terminated abnormally it may leave a communication
  121. #   pipe file in /tmp.
  122.  
  123.  
  124. record board( pcs, cmv, cnm, caswq, caswk, casbq, casbk, fepp, ply)
  125.  
  126. global    Me, Yu, Mycname, Yrcname, Mycomm, Yrcomm, Logname, Logfile,
  127.     Mycol, Yrcol, Blind, Bg, Frinclst, Lmv, Any, Tries, Remind
  128.  
  129.  
  130. procedure automov( )
  131.  
  132. #   Returns a pseudo-randomly selected move type-in to be used in
  133. #   "auto opponent" mode.  But if possible, try to recapture (unless in
  134. #   blind mode):
  135.  
  136.     local    m, ms
  137.     static    anyflag
  138.  
  139.     initial    anyflag := 0
  140.  
  141.     if anyflag = 0 then {
  142.     anyflag := 1
  143.     return "any"
  144.     }
  145.     anyflag := 0
  146.  
  147.     ms := set( )
  148.     every insert( ms, movgen( Bg))
  149.  
  150.     if / Any then {
  151.     if find( ":", \ Lmv) & not find( "ep", \ Lmv) & / Blind then {
  152.         every m := ! ms do {
  153.         if m[ 4:6] == Lmv[ 4:6]  & movlegal( Bg, m) then
  154.             return m[ 2:6] || "Q"
  155.         }
  156.         }
  157.     while * ms ~= 0 do {
  158.         if movlegal( Bg, m := ? ms) then
  159.         return m[ 2:6] || "Q"
  160.         delete( ms, m)
  161.         }
  162.     return "end"
  163.     }
  164.     else {
  165.     every m := ! ms do {
  166.         if m[ 1] == "P" & m[ 6] == ":" & movlegal( Bg, m) then
  167.         return m[ 2:6] || "Q"
  168.         }
  169.     return "end"
  170.     }
  171. end
  172.  
  173.  
  174. procedure chksqrs( b)
  175.  
  176. #   Generates the set of squares of pieces giving check in board b;
  177. #   fails if moving side's king not in check:
  178.  
  179.     local    sk
  180.  
  181.     sk := find( pc2p( "K", b.cmv), b.pcs)
  182.     suspend sqratks( b.pcs, sk, b.cnm)
  183. end
  184.  
  185.  
  186. procedure fr2s( file, rank)
  187.  
  188. #   Returns the square number corresponding to "file" and "rank"
  189. #   numbers; fails if invalid file and/or rank:
  190.  
  191.     return (0 < (9 > file)) + 8 * (0 < ( 9 > rank)) - 8
  192. end
  193.  
  194.  
  195. procedure gamend( b)
  196.  
  197. #   If the position b is at end of game,
  198. #   return an ascii string giving the result; otherwise, fail:
  199.  
  200.     local    nbn, sk
  201.  
  202.     sk := find( pc2p( "K", b.cmv), b.pcs)
  203.  
  204.     if not movlegal( b, movgen( b, sk)) & not movlegal( b, movgen( b)) then {
  205.     if chksqrs( b) then {
  206.         if b.cnm[ 1] == "W" then
  207.         return "1-0"
  208.         else
  209.         return "0-1"
  210.         }
  211.     else
  212.         return "1/2-1/2"
  213.     }
  214.     else if not upto( 'PRQprq', b.pcs) then {
  215.     nbn := 0
  216.     every upto( 'NBnb', b.pcs) do
  217.         nbn +:= 1
  218.     if nbn < 2 then
  219.         return "1/2-1/2"
  220.     }
  221. end
  222.     
  223.  
  224. procedure init( )
  225.  
  226. #   init initializes the program:
  227.  
  228.     local    whopipe, line, namdelim
  229.  
  230. #   Setup a data table for move generation:
  231.  
  232.     Frinclst := table( )
  233.     Frinclst[ "R"] := [ [1, 0],  [0, 1],  [-1, 0],  [0, -1] ]
  234.     Frinclst[ "N"] := [ [2, 1], [1, 2], [-1, 2], [-2, 1],
  235.             [-2, -1], [-1, -2], [1, -2], [2, -1] ]
  236.     Frinclst[ "B"] := [ [1, 1],  [-1, 1],  [-1, -1],  [1, -1] ]
  237.     Frinclst[ "Q"] := Frinclst[ "R"] ||| Frinclst[ "B"]
  238.     Frinclst[ "K"] := Frinclst[ "Q"]
  239.     Frinclst[ "r"] := Frinclst[ "R"]
  240.     Frinclst[ "n"] := Frinclst[ "N"]
  241.     Frinclst[ "b"] := Frinclst[ "B"]
  242.     Frinclst[ "q"] := Frinclst[ "Q"]
  243.     Frinclst[ "k"] := Frinclst[ "K"]
  244.  
  245. #   Setup a character set to delimit user names:
  246.  
  247.     namdelim := ~(&letters ++ &digits ++ '_.-')
  248.  
  249. #   Set reminder bell flag to off:
  250.  
  251.     Remind := ""
  252.  
  253. #   Set random number seed:
  254.  
  255.     &random := integer( map( "hxmysz", "hx:my:sz", &clock))
  256.  
  257. #   Get my name from user or "who am I" command and issue greeting:
  258.  
  259.     writes( "Your name (up to 8 letters & digits; default = user name)? ")
  260.     line := read( ) | kstop( "can't read user name")
  261.     Me := tokens( line, namdelim)
  262.     if /Me then {
  263.     whopipe := open( "who am i | awk '{print $1}' | sed 's/^.*!//'", "rp")
  264.     Me := tokens( read( whopipe), namdelim)
  265.     close( \whopipe)
  266.     }
  267.     if /Me then
  268.     write( "Can't get user name from system.")
  269.     while /Me do {
  270.     writes( "Your name? ")
  271.     line := read( ) | kstop( "can't get user name")
  272.     Me := tokens( line, namdelim)
  273.     }
  274.     write( "Welcome, ", Me, ", to Kriegspiel (double blind chess).")
  275.  
  276. #   Prompt user to enter color:
  277.  
  278.     while writes( "Your color (w or b)? ") do {
  279.     line := read( ) | kstop( "can't read color")
  280.     if find( line[ 1], "WwBb") then
  281.         break
  282.     }
  283.     Mycol := (find( line[ 1], "Ww"), "White") | "Black"
  284.     Yrcol := map( Mycol, "WhiteBlack", "BlackWhite")
  285.  
  286. #   Prompt user to enter opponent name:
  287.  
  288.     writes( "Enter opponent's name (default = auto): ")
  289.     Yu := tokens( read( ), namdelim) | "auto"
  290.  
  291. #   Prompt user to select "blind" mode, if desired:
  292.  
  293.     writes( "Totally blind mode (default is no)? ")
  294.     Blind := find( (tokens( read( )) \ 1)[ 1], "Yy")
  295.  
  296. #   Set communication file names and create my communication file:
  297.  
  298.     if Yu == "auto" then {
  299.     Mycname := "/dev/null"
  300.     Yrcname := "/dev/null"
  301.     }
  302.     else {
  303.     Mycname := "/tmp/krcom" || Mycol[ 1] || Me
  304.     Yrcname := "/tmp/krcom" || Yrcol[ 1] || Yu
  305.     remove( Mycname)
  306.     system( "/etc/mknod " || Mycname || " p && chmod 644 " ||
  307.         Mycname) = 0 | kstop( "can't create my comm file")
  308.     }
  309.  
  310. #   Get name of my log file, open it, then remove from directory:
  311.  
  312.     Logname := "/tmp/krlog" || Mycol[ 1] || Me
  313.     while /Logfile do {
  314.     writes( "Log file name (defaults to ", Logname, ")? ")
  315.     line := read( ) | kstop( "can't read log file name")
  316.     Logname := tokens( line)
  317.     Logfile := open( Logname, "cr")
  318.     }
  319.     remove( Logname)
  320.  
  321. #   Open our communication files, trying to avoid deadlock:
  322.  
  323.     write( "Attempting to establish communication with ", Yu)
  324.     if Mycol == "White" then
  325.     Mycomm := open( Mycname, "w") | kstop( "can't open my comm file")
  326.     while not (Yrcomm := open( Yrcname)) do {
  327.     write( "Still attempting to establish communication")
  328.     if system( "sleep 3") ~= 0 then
  329.         kstop( "gave up on establishing communications")
  330.     }
  331.     if Mycol == "Black" then
  332.     Mycomm := open( Mycname, "w") | kstop( "can't open my comm file")
  333.  
  334. #   Initialize board and moves:
  335.  
  336.     Bg := board(
  337.  
  338.     "RNBQKBNRPPPPPPPP                                pppppppprnbqkbnr",
  339.     "White", "Black", "W-Q", "W-K", "B-Q", "B-K", &null, 0)
  340.  
  341. #   Initialize set of move tries:
  342.  
  343.     Tries := set( )
  344.  
  345.     write( Logfile, "Kriegspiel game begins ", &dateline)
  346.     write( Logfile, Me, " is ", Mycol, "; ", Yu, " is ", Yrcol)
  347.     \ Blind & write( Logfile, Me, " is in 'totally blind' mode!")
  348.  
  349.     write( "You have the ", Mycol, " pieces against ", Yu)
  350.     \ Blind & write( "You have chosen to play in 'totally blind' mode!")
  351.     write( "At the \"Try\" prompt you may type help for assistance.")
  352.     write( "Initialization complete; awaiting first white move.")
  353.     return
  354. end
  355.  
  356.  
  357. procedure kstop( s)
  358.  
  359. #   Clean up and terminate execution with message s:
  360.  
  361.     local    logtemp
  362.  
  363.     close( \Mycomm)
  364.     remove( \Mycname)
  365.     write( \Logfile, "Kriegspiel game ends ", &dateline)
  366.     logboard( \ Logfile, \ Bg)
  367.     if seek( \Logfile) then {
  368.     logtemp := open( Logname, "w") | kstop( "can't open my log file")
  369.     every write( logtemp, ! Logfile)
  370.     write( "Game log is on file ", Logname)
  371.     }
  372.     stop( "Kriegspiel stop: ", s)
  373. end
  374.  
  375.  
  376. procedure logboard( file, b)
  377.  
  378. #   Print the full board position in b to file:
  379.  
  380.     local    f, r, p
  381.  
  382.     write( file, "Current board position:")
  383.     write( file, " a  b  c  d  e  f  g  h")
  384.     every r := 8 to 1 by -1 do {
  385.     write( file, "-------------------------")
  386.     every writes( file, "|", p2c( p := b.pcs[ fr2s( 1 to 8, r)])[ 1],
  387.         pc2p( p, "W"))
  388.     write( file, "|", r)
  389.     }
  390.     write( file, "-------------------------")
  391.     writes( file, b.cmv, " to move;")
  392.     writes( file, " enp file: ", "abcdefgh"[ \ b.fepp], ";")
  393.     writes( file, " castle mvs ", b.caswq || " " || b.caswk || " " ||
  394.     b.casbq || " " || b.casbk, ";")
  395.     write( file, " half-mvs played ", b.ply)
  396.     write( file, "")
  397. end
  398.  
  399.  
  400. procedure main( )
  401.  
  402.     local    line
  403.  
  404. #   Initialize player names and colors and establish communications:
  405.  
  406.     init( )
  407.  
  408. #   Loop validating our moves and processing opponent responses:
  409.  
  410.     repeat {
  411.     while Mycol == Bg.cmv do {
  412.         writes( Remind, "Try your (", Me, "'s) move # ",
  413.         Bg.ply / 2 + 1, ": ")
  414.         line := read( ) | kstop( "player read fail")
  415.         write( Mycomm, line)
  416.         write( Logfile, Me, " typed: ", line)
  417.         line := map( tokens( line)) | ""
  418.         case line of {
  419.         ""            : 0
  420.         left( "any", *line)    : myany( )
  421.         left( "board", *line)    : myboard( )
  422.         "end"            : myend( )
  423.         left( "help", *line)    : myhelp( )
  424.         left( "message", *line)    : mymessage( )
  425.         left( "remind", *line)    : myremind( )
  426.         default            : mytry( line)
  427.         }
  428.         }
  429.     while Yrcol == Bg.cmv do {
  430.         if Yu == "auto" then
  431.         line := automov( )
  432.         else
  433.         line := read( Yrcomm) | kstop( "opponent read fail")
  434.         write( Logfile, Yu, " typed: ", line)
  435.         line := map( tokens( line)) | ""
  436.         case line of {
  437.         ""            : 0
  438.         left( "any", *line)    : yrany( )
  439.         left( "board", *line)    : 0
  440.         "end"            : yrend( )
  441.         left( "help", *line)    : 0
  442.         left( "message", *line)    : yrmessage( )
  443.         left( "remind", *line)    : 0
  444.         default            : yrtry( line)
  445.         }
  446.         }
  447.     }
  448. end
  449.  
  450.  
  451. procedure movgen( b, s)
  452.  
  453. #   movgen generates the pseudo-legal moves in board position b from the
  454. #   piece on square s; if s is unspecified all pieces are considered.
  455. #   Note: pseudo-legal here means that the legality of the move has been
  456. #   determined up to the question of whether it leaves the moving side's
  457. #   king in check:
  458.  
  459.     local    r, f, p, snfr, m, fto, rto, sl, sh,
  460.         sto, fril, rp, r2, r4, r5, r7, ps
  461.  
  462.     ps := b.pcs
  463.  
  464.     sl := (\s | 1)
  465.     sh := (\s | 64)
  466.  
  467.     every s := sl to sh do {
  468.     if p2c( p := ps[ s]) == b.cmv then {
  469.         f := s2f( s)
  470.         r := s2r( s)
  471.         snfr := s2sn( s)
  472.  
  473. #   Pawn moves:
  474.  
  475.         if find( p, "Pp") then {
  476.         if p == "P" then {
  477.             rp :=  1; r2 := 2; r4 := 4; r5 := 5; r7 := 7
  478.             }
  479.         else {
  480.             rp := -1; r2 := 7; r4 := 5; r5 := 4; r7 := 2
  481.             }
  482.         if ps[ sto := fr2s( f, r + rp)] == " " then {
  483.             m := "P" || snfr || s2sn( sto)
  484.             if r = r7 then
  485.             suspend m || ! "RNBQ"
  486.             else {
  487.             suspend m
  488.             if r = r2 & ps[ sto := fr2s( f, r4)] == " " then
  489.                 suspend "P" || snfr || s2sn( sto)
  490.             }
  491.             }
  492.         every fto := 0 < (9 > (f - 1 to f + 1 by 2)) do {
  493.             m := "P" || snfr ||
  494.             s2sn( sto := fr2s( fto, r + rp)) || ":"
  495.             if p2c( ps[ sto]) == b.cnm then {
  496.             if r = r7 then
  497.                 every suspend m || ! "RNBQ"
  498.             else
  499.                 suspend m
  500.             }
  501.             if r = r5 & fto = \ b.fepp then
  502.             suspend m || "ep"
  503.             }
  504.         }
  505.  
  506. #   Sweep piece (rook, bishop, queen) moves:
  507.  
  508.         else if find( p, "RBQrbq") then {
  509.         every fril := ! Frinclst[ p] do {
  510.             fto := f
  511.             rto := r
  512.             while sto := fr2s( fto +:= fril[ 1], rto +:= fril[ 2]) do {
  513.             if ps[ sto] == " " then
  514.                 suspend pc2p( p, "W") || snfr || s2sn( sto)
  515.             else {
  516.                 if p2c( ps[ sto]) == b.cnm then
  517.                 suspend pc2p( p, "W") ||
  518.                     snfr || s2sn( sto) || ":"
  519.                 break
  520.                 }
  521.             }
  522.             }
  523.         }
  524.  
  525. #   Knight and king moves:
  526.  
  527.         else if find( p, "KNkn") then {
  528.         every fril := ! Frinclst[ p] do {
  529.             if sto := fr2s( f + fril[ 1], r + fril[ 2]) then {
  530.             if p2c( ps[ sto]) == b.cnm then
  531.                 suspend pc2p( p, "W") ||
  532.                 snfr || s2sn( sto) || ":"
  533.             else if ps[ sto] == " " then
  534.                 suspend pc2p( p, "W") || snfr || s2sn( sto)
  535.             }
  536.             }
  537.         if p == "K" then {
  538.             if (b.caswq ~== "", ps[ sn2s( "b1") : sn2s( "e1")] == "   ",
  539.             not sqratks( ps, sn2s( "d1"), "Black"),
  540.             not sqratks( ps, sn2s( "e1"), "Black")) then
  541.                 suspend "Ke1c1cas"
  542.             if (b.caswk ~== "", ps[ sn2s( "f1") : sn2s( "h1")] == "  ",
  543.             not sqratks( ps, sn2s( "f1"), "Black"),
  544.             not sqratks( ps, sn2s( "e1"), "Black")) then
  545.                 suspend "Ke1g1cas"
  546.             }
  547.         else if p == "k" then {
  548.             if (b.casbq ~== "", ps[ sn2s( "b8") : sn2s( "e8")] == "   ",
  549.             not sqratks( ps, sn2s( "d8"), "White"),
  550.             not sqratks( ps, sn2s( "e8"), "White")) then
  551.                 suspend "Ke8c8cas"
  552.             if (b.casbk ~== "", ps[ sn2s( "f8") : sn2s( "h8")] == "  ",
  553.             not sqratks( ps, sn2s( "f8"), "White"),
  554.             not sqratks( ps, sn2s( "e8"), "White")) then
  555.                 suspend "Ke8g8cas"
  556.             }
  557.         }
  558.         }
  559.     }
  560. end
  561.  
  562.  
  563. procedure movlegal( b, m)
  564.  
  565. #   Tests move m on board b and, if it does not leave the moving color in
  566. #   check, returns m; fails otherwise:
  567.  
  568.     local    ps, sfr, sto, sk
  569.  
  570.     ps := b.pcs
  571.     sfr := sn2s( m[ 2:4])
  572.     sto := sn2s( m[ 4:6])
  573.  
  574. #   Castling move:
  575.  
  576.     if m[ 6:9] == "cas" then {
  577.     if m == "Ke1c1cas" then
  578.         return not sqratks( ps, sn2s( "c1"), "Black") & m
  579.     if m == "Ke1g1cas" then
  580.         return not sqratks( ps, sn2s( "g1"), "Black") & m
  581.     if m == "Ke8c8cas" then
  582.         return not sqratks( ps, sn2s( "c8"), "White") & m
  583.     if m == "Ke8g8cas" then
  584.         return not sqratks( ps, sn2s( "g8"), "White") & m
  585.     }
  586.  
  587. #   Enpassant pawn capture:
  588.  
  589.     if m[ 6:9] == ":ep" then
  590.     ps[ fr2s( s2f( sto), s2r( sfr))] := " "
  591.  
  592. #   All non-castling moves:
  593.  
  594.     ps[ sto] := ps[ sfr]
  595.     ps[ sfr] := " "
  596.     sk := find( pc2p( "K", b.cmv), ps)
  597.     return not sqratks( ps, sk, b.cnm) & m
  598.  
  599. end
  600.  
  601.  
  602. procedure movmake( b, m)
  603.  
  604. #   Makes move m on board b:
  605.  
  606.     local    sfr, sto
  607.  
  608.     if m == "Ke1c1cas" then {
  609.     b.pcs[ sn2s( "a1")] := " "
  610.     b.pcs[ sn2s( "d1")] := "R"
  611.     }
  612.     else if m == "Ke1g1cas" then {
  613.     b.pcs[ sn2s( "h1")] := " "
  614.     b.pcs[ sn2s( "f1")] := "R"
  615.     }
  616.     else if m == "Ke8c8cas" then {
  617.     b.pcs[ sn2s( "a8")] := " "
  618.     b.pcs[ sn2s( "d8")] := "r"
  619.     }
  620.     else if m == "Ke8g8cas" then {
  621.     b.pcs[ sn2s( "h8")] := " "
  622.     b.pcs[ sn2s( "f8")] := "r"
  623.     }
  624.  
  625.     sfr := sn2s( m[ 2:4])
  626.     sto := sn2s( m[ 4:6])
  627.     b.pcs[ sto] := b.pcs[ sfr]
  628.     b.pcs[ sfr] := " "
  629.  
  630.     if find( m[ -1], "rnbqRNBQ") then
  631.     b.pcs[ sto] := pc2p( m[ -1], b.cmv)
  632.  
  633.     if sfr = sn2s( "e1") then    b.caswq := b.caswk := ""
  634.     if sfr = sn2s( "e8") then    b.casbq := b.casbk := ""
  635.  
  636.     if (sfr | sto) = sn2s( "a1") then    b.caswq := ""
  637.     if (sfr | sto) = sn2s( "h1") then    b.caswk := ""
  638.     if (sfr | sto) = sn2s( "a8") then    b.casbq := ""
  639.     if (sfr | sto) = sn2s( "h8") then    b.casbk := ""
  640.  
  641.     if m[ 6:9] == ":ep" then
  642.     b.pcs[ fr2s( s2f( sto), s2r( sfr))] := " "
  643.  
  644.     b.fepp := &null
  645.     if m[ 1] == "P" & abs( s2r( sfr) - s2r( sto)) = 2 then
  646.     b.fepp := s2f( sto)
  647.  
  648.     b.ply +:= 1
  649.     b.cmv :=: b.cnm
  650. end
  651.  
  652.  
  653. procedure movtry( m)
  654.  
  655. #   Tests whether the typed move m is legal in the global board Bg and, if so,
  656. #   returns the corresponding move returned from movgen (which will be in a
  657. #   different format with piece letter prefix, etc.).  Fails if m is not
  658. #   legal.  Note that if the any flag is set, only captures by pawns are
  659. #   allowed:
  660.  
  661.     local    ml, mt, sfr, sto
  662.  
  663.     mt := map( tokens( m)) | ""
  664.     if mt == "o-o" then
  665.     mt := (Bg.cmv == "White", "e1g1") | "e8g8"
  666.     else if mt == "o-o-o" then
  667.     mt := (Bg.cmv == "White", "e1c1") | "e8c8"
  668.  
  669.     sfr := sn2s( mt[ 1:3]) | fail
  670.     sto := sn2s( mt[ 3:5]) | fail
  671.  
  672.     if find( mt[ 5], "rnbq") then
  673.     mt[ 5] := map( mt[ 5], "rnbq", "RNBQ")
  674.     else mt := mt[ 1:5] || "Q"
  675.     
  676.     if \ Any then {
  677.     if Bg.pcs[ sfr] ~== pc2p( "P", Bg.cmv) then fail
  678.     every ml := movgen( Bg, sfr) do {
  679.         if ml[ 4:7] == mt[ 3:5] || ":" then {
  680.         if find( ml[ -1], "RNBQ") then
  681.             ml[ -1] := mt[ 5]
  682.         return movlegal( Bg, ml)
  683.         }
  684.         }
  685.     }
  686.     else {
  687.     every ml := movgen( Bg, sfr) do {
  688.         if ml[ 4:6] == mt[ 3:5] then {
  689.         if find( ml[ -1], "RNBQ") then
  690.             ml[ -1] := mt[ 5]
  691.         return movlegal( Bg, ml)
  692.         }
  693.         }
  694.     }
  695. end
  696.  
  697.  
  698. procedure myany( )
  699.  
  700. #   Process my any command.
  701. #   Check for captures by pawns and inform the player of any, and, if
  702. #   at least one, set Any flag to require that player try only captures
  703. #   by pawns:
  704.  
  705.     local    m, p, s
  706.  
  707.     if \ Any then {
  708.     write( "You have already asked 'Any' and received yes answer!")
  709.     fail
  710.     }
  711.  
  712.     p := pc2p( "P", Bg.cmv)
  713.     if movlegal( Bg, 1( m := movgen( Bg, 1(s := 9 to 56, Bg.pcs[ s] == p)),
  714.         m[ 6] == ":")) then {
  715.     write( "Yes; you must now make a legal capture by a pawn.")
  716.     Any := "Yes"
  717.     }
  718.     else
  719.     write( "No.")
  720. end
  721.  
  722.  
  723. procedure myboard( )
  724.  
  725. #   Process my board command by printing the board but omitting the
  726. #   opponent's pieces and the enpassant status; a count of pieces of
  727. #   both colors is printed:
  728. #   Note: no board printed in blind mode.
  729.  
  730.     local    f, r, p, nw, nb
  731.  
  732.     \ Blind & write( "Sorry; no board printout in blind mode!") & fail
  733.  
  734.     write( "Current board position (your pieces only):")
  735.     write( " a  b  c  d  e  f  g  h")
  736.     every r := 8 to 1 by -1 do {
  737.     write( "-------------------------")
  738.     every f := 1 to 8 do {
  739.         if (p2c( p := Bg.pcs[ fr2s( f, r)])) == Mycol then
  740.         writes( "|", Mycol[ 1], pc2p( p, "W"))
  741.         else
  742.         writes( "|  ")
  743.         }
  744.     write( "|", r)
  745.     }
  746.     write( "-------------------------")
  747.     writes( Bg.cmv, " to move; ")
  748.     writes( "castle mvs ", (Mycol == "White", Bg.caswq || " " || Bg.caswk) |
  749.     Bg.casbq || " " || Bg.casbk)
  750.     write( "; half-mvs played ", Bg.ply)
  751.     nw := nb := 0
  752.     every upto( &ucase, Bg.pcs) do nw +:= 1
  753.     every upto( &lcase, Bg.pcs) do nb +:= 1
  754.     write( nw, " White pieces, ", nb, " Black.")
  755.     write( "")
  756. end
  757.  
  758.  
  759. procedure myend( )
  760.  
  761. #   Process my end command:
  762.  
  763.     kstop( "by " || Me)
  764. end
  765.  
  766.  
  767. procedure myhelp( )
  768.  
  769. #   Process my help command:
  770.  
  771.     write( "")
  772.     write( "This is \"Kriegspiel\" (war play), a game of chess between two")
  773.     write( "opponents who do not see the location of each other's pieces.")
  774.     write( "Note: the moves of the special opponent 'auto' are played by the")
  775.     write( "program itself.  Currently, auto plays at a low novice level.")
  776.     write( "When it is your turn to move, you will be prompted to type")
  777.     write( "a move attempt or one of several commands.  To try a move,")
  778.     write( "type the from and to squares in algebraic notation, as in: e2e4")
  779.     write( "or b8c6.  Castling may be typed as o-o, o-o-o, or as the move")
  780.     write( "of the king, as in: e8g8.  Pawn promotions should look like")
  781.     write( "d7d8Q.  If omitted, the piece promoted to is assumed to be a")
  782.     write( "queen.  Letters may be in upper or lower case.  If the move is")
  783.     write( "legal, it stands, and the opponent's response is awaited.")
  784.     write( "If the move is illegal, the program will prompt you to")
  785.     write( "try again.  If the move is illegal because of the opponent's")
  786.     write( "position but not impossible based on the position of your")
  787.     write( "pieces, then your opponent will be informed that you tried")
  788.     write( "an illegal move (note: this distinction between illegal and")
  789.     write( "impossible is somewhat tricky and the program may, in some")
  790.     write( "cases, not get it right).  The program will announce the")
  791.     write( "result and terminate execution when the game is over.  You may")
  792.     write( "then inspect the game log file which the program generated.")
  793.     write( "")
  794.  
  795.     writes( "Type empty line for more or 'q' to return from help: ")
  796.     if map( read( ))[ 1] == "q" then
  797.     fail
  798.  
  799.     write( "")
  800.     write( "The program will let you know of certain events that take place")
  801.     write( "during the game.  For each capture move, both players will be")
  802.     write( "informed of the location of the captured piece.  The opponent")
  803.     write( "will be informed of a pawn promotion but not of the piece")
  804.     write( "promoted to or the square on which the promotion takes place.")
  805.     write( "When a player gives check, both players will be informed of the")
  806.     write( "event and of some information about the direction from which the")
  807.     write( "check arises, as in: check on the rank', 'check on the file',")
  808.     write( "'check on the + diagonal', 'check on the - diagonal', or 'check")
  809.     write( "by a knight'.  For a double check, both directions are given.")
  810.     write( "(A + diagonal is one on which file letters and rank numbers")
  811.     write( "increase together, like a1-h8, and a - diagonal is one in which")
  812.     write( "file letters increase while rank numbers decrease, as in a8-h1).")
  813.     write( "")
  814.     write( "Note: if you have selected the 'blind' mode, then you will")
  815.     write( "receive no information about checks, captures, or opponent")
  816.     write( "'any' or illegal move tries; nor will you be able to print")
  817.     write( "the board.  You will not even be told when your own pieces")
  818.     write( "are captured.  Except for answers to 'any' commands, the")
  819.     write( "program will inform you only of when you have moved, when")
  820.     write( "your opponent has moved, and of the result at end of game.")
  821.     write( "")
  822.  
  823.     writes( "Type empty line for more or 'q' to return from help: ")
  824.     if map( read( ))[ 1] == "q" then
  825.     fail
  826.  
  827.     write( "")
  828.     write( "Description of commands; note: upper and lower case letters")
  829.     write( "are not distinguished, and every command except 'end' may be") 
  830.     write( "abbreviated.")
  831.     write( "")
  832.     write( "any")
  833.     write( "")
  834.     write( "The 'any' command is provided to speed up the process of trying")
  835.     write( "captures by pawns.  Since pawns are the only pieces that capture")
  836.     write( "in a different manner from the way they ordinarily move, it is")
  837.     write( "often useful to try every possible capture, since such a move")
  838.     write( "can only be legal if it in fact captures something.  Since the")
  839.     write( "process of trying the captures can be time-consuming, the 'any'")
  840.     write( "command is provided to signal your intent to try captures by")
  841.     write( "pawns until you find a legal one.  The program will tell you if")
  842.     write( "you have at least one.  If you do then you must try captures by")
  843.     write( "pawns (in any order) until you find a legal one.  Note that the")
  844.     write( "opponent will be informed of your plausible 'any' commands (that")
  845.     write( "is, those that are not impossible because you have no pawns on")
  846.     write( "the board).")
  847.     write( "")
  848.  
  849.     writes( "Type empty line for more or 'q' to return from help: ")
  850.     if map( read( ))[ 1] == "q" then
  851.     fail
  852.  
  853.     write( "")
  854.     write( "board")
  855.     write( "")
  856.     write( "The 'board' command prints the current position of your")
  857.     write( "pieces only, but also prints a count of pieces of both sides.")
  858.     write( "Note: 'board' is disallowed in blind mode.")
  859.     write( "")
  860.     write( "end")
  861.     write( "")
  862.     write( "Then 'end' command informs the program and your")
  863.     write( "opponent of your decision to terminate the game")
  864.     write( "immediately.")
  865.     write( "")
  866.     write( "help")
  867.     write( "")
  868.     write( "The 'help' command prints this information.")
  869.     write( "")
  870.  
  871.     writes( "Type empty line for more or 'q' to return from help: ")
  872.     if map( read( ))[ 1] == "q" then
  873.     fail
  874.  
  875.     write( "")
  876.     write( "message")
  877.     write( "")
  878.     write( "The 'message' command allows you to send a one-line")
  879.     write( "message to your opponent.  Your opponent will be prompted")
  880.     write( "for a one-line response.  'message' may be useful for such")
  881.     write( "things as witty remarks, draw offers, etc.")
  882.     write( "")
  883.     write( "remind")
  884.     write( "")
  885.     write( "The 'remind' command turns on (if off) or off (if on) the")
  886.     write( "bell that is rung when the program is ready to accept your")
  887.     write( "move or command.  The bell is initially off.")
  888.     write( "")
  889.  
  890. end
  891.  
  892.  
  893. procedure mymessage( )
  894.  
  895. #   Process my message command:
  896.  
  897.     local    line
  898.  
  899.     write( "Please type a one-line message:")
  900.     line := read( ) | kstop( "can't read message")
  901.     write( Mycomm, line)
  902.     write( Logfile, line)
  903.     write( "Awaiting ", Yu, "'s response")
  904.     if Yu == "auto" then
  905.     line := "I'm just your auto opponent."
  906.     else
  907.     line := read( Yrcomm) | kstop( "can't read message response")
  908.     write( Yu, " answers: ", line)
  909.     write( Logfile, line)
  910. end
  911.  
  912.  
  913. procedure myremind( )
  914.  
  915. #   Process my remind command:
  916.  
  917.     if Remind == "" then
  918.     Remind := "\^g"
  919.     else
  920.     Remind := ""
  921. end
  922.  
  923.  
  924. procedure mytry( mt)
  925.  
  926. #   Process my move try mt:
  927.  
  928.     local    ml, result
  929.  
  930.     if ml := movtry( mt) then {
  931.     Lmv := ml
  932.     write( Me, " (", Mycol, ") has moved.")
  933.     write( Logfile, Me, "'s move ", Bg.ply / 2 + 1, " is ", ml)
  934.     / Blind & write( Me, " captures on ", s2sn( sqrcap( Bg, ml)))
  935.     movmake( Bg, ml)
  936.     / Blind & saycheck( )
  937.     Any := &null
  938.     Tries := set( )
  939.     if result := gamend( Bg) then {
  940.         write( "Game ends; result: ", result)
  941.         write( Logfile, "Result: ", result)
  942.         kstop( "end of game")
  943.         }
  944.     }
  945.     else
  946.     write( "Illegal move, ", Me, "; try again:")
  947. end
  948.  
  949.  
  950. procedure p2c( p)
  951.  
  952. #   Returns "White" if p is white piece code ("PRNBQK"), "Black"
  953. #   if p is black piece code ("prnbqk"), and " " if empty square
  954. #   (" "):
  955.  
  956.     if find( p, "PRNBQK") then
  957.     return "White"
  958.     else if find( p, "prnbqk") then
  959.     return "Black"
  960.     else
  961.     return " "
  962. end
  963.  
  964.  
  965. procedure pc2p( p, c)
  966.  
  967. #   Returns the piece letter for the piece of type p but color c;
  968. #   returns " " if p == " ".  Thus pc2p( "R", "Black") == "r".
  969. #   c may be abbreviated to "W" or "B":
  970.  
  971.     if c[ 1] == "W" then
  972.     return map( p, "prnbqk", "PRNBQK")
  973.     else
  974.     return map( p, "PRNBQK", "prnbqk")
  975. end
  976.  
  977.  
  978. procedure s2f( square)
  979.  
  980. #   Returns the file number of the square number "square"; fails
  981. #   if invalid square number:
  982.  
  983.     return ( (0 < ( 65 > integer( square))) - 1) % 8 + 1
  984. end
  985.  
  986.  
  987. procedure s2r( square)
  988.  
  989. #   Returns the rank number of the square number "square"; fails
  990. #   if invalid square number:
  991.  
  992.     return ( (0 < ( 65 > integer( square))) - 1) / 8 + 1
  993. end
  994.  
  995.  
  996. procedure s2sn( square)
  997.  
  998. #   Returns the algebraic square name corresponding to square number
  999. #   "square"; fails if invalid square number:
  1000.  
  1001.     return "abcdefgh"[ s2f( square)] || string( s2r( square))
  1002. end
  1003.  
  1004.  
  1005. procedure saycheck( )
  1006.  
  1007. #   Announce checks, if any, in global board Bg:
  1008.  
  1009.     local    s, sk
  1010.  
  1011.     sk := find( pc2p( "K", Bg.cmv), Bg.pcs)
  1012.  
  1013.     every s := chksqrs( Bg) do {
  1014.     writes( (Mycol == Bg.cnm, Me) | Yu, " checks ")
  1015.     if s2r( s) == s2r( sk) then
  1016.         write( "on the rank.")
  1017.     else if s2f( s) == s2f( sk) then
  1018.         write( "on the file.")
  1019.     else if ( s2f( s) - s2f( sk)) = ( s2r( s) - s2r( sk)) then
  1020.         write( "on the + diagonal.")
  1021.     else if ( s2f( s) - s2f( sk)) = ( s2r( sk) - s2r( s)) then
  1022.         write( "on the - diagonal.")
  1023.     else
  1024.         write( "by knight.")
  1025.     }
  1026. end
  1027.  
  1028.  
  1029. procedure sn2s( sn)
  1030.  
  1031. #   Returns the square number corresponding to the algebraic square
  1032. #   name sn; examples: sn2s( "a1") = 1, sn2s( "b1") = 2, sn2s( "h8") = 64.
  1033. #   Fails if invalid square name:
  1034.  
  1035.     return find( sn[ 1], "abcdefgh") + 8 * (0 < (9 > integer( sn[ 2]))) - 8
  1036. end
  1037.  
  1038.  
  1039. procedure sqratks( ps, s, c)
  1040.  
  1041. #   Generates the numbers of squares of pieces of color c that "attack"
  1042. #   square s in board piece array ps; fails if no such squares:
  1043.  
  1044.     local    file, rank, rfr, sfr, fril, p, ffr
  1045.  
  1046.     file := s2f( s)
  1047.     rank := s2r( s)
  1048.  
  1049. #   Check for attacks from pawns:
  1050.  
  1051.     rfr := (c == "White", rank - 1) | rank + 1
  1052.     every sfr := fr2s( file - 1 to file + 1 by 2, rfr) do {
  1053.     if ps[ sfr] == pc2p( "P", c) then
  1054.         suspend sfr
  1055.     }
  1056.  
  1057. #   Check for attack from king or knights:
  1058.  
  1059.     every fril := ! Frinclst[ p := ("K" | "N")] do {
  1060.     if sfr := fr2s( file + fril[ 1], rank + fril[ 2]) then {
  1061.         if ps[ sfr] == pc2p( p, c) then
  1062.         suspend sfr
  1063.         }
  1064.     }
  1065.  
  1066. #   Check for attacks from sweep (rook and bishop) directions:
  1067.  
  1068.     every fril := ! Frinclst[ p := ("R" | "B")] do {
  1069.     ffr := file
  1070.     rfr := rank
  1071.     while sfr := fr2s( ffr +:= fril[ 1], rfr +:= fril[ 2]) do {
  1072.         if ps[ sfr] ~== " " then {
  1073.         if ps[ sfr] == pc2p( p | "Q", c) then
  1074.             suspend sfr
  1075.         break
  1076.         }
  1077.         }
  1078.     }
  1079. end
  1080.  
  1081.  
  1082. procedure sqrcap( b, m)
  1083.  
  1084. #   Returns square of piece captured by move m in board b; fails if m
  1085. #   not a capture:
  1086.  
  1087.     local    fto, rfr
  1088.  
  1089.     if m[ 6:9] == ":ep" then {
  1090.     fto := find( m[ 4], "abcdefgh")
  1091.     rfr := integer( m[ 3])
  1092.     return fr2s( fto, rfr)
  1093.     }
  1094.     else if m[ 6] == ":" then
  1095.     return sn2s( m[ 4:6])
  1096. end
  1097.  
  1098.  
  1099. procedure tokens( s, d)
  1100.  
  1101. #   Generate tokens from left to right in string s given delimiters in cset
  1102. #   d, where a token is a contiguous string of 1 or more characters not in
  1103. #   d bounded by characters in d or the left or right end of s.
  1104. #   d defaults to ' \t'.
  1105.  
  1106.     s := string( s) | fail
  1107.     d := (cset( d) | ' \t')
  1108.  
  1109.     s ? while tab( upto( ~d)) do
  1110.     suspend( tab( many( ~d)) \ 1)
  1111. end
  1112.  
  1113.  
  1114. procedure yrany( )
  1115.  
  1116. #   Process opponent's any command:
  1117.  
  1118.     local    m, p, s
  1119.  
  1120.     if \ Any then fail
  1121.  
  1122.     p := pc2p( "P", Bg.cmv)
  1123.     if not find( p, Bg.pcs) then fail
  1124.  
  1125.     / Blind & writes( Yu, " asked 'any' and was told ")
  1126.  
  1127.     if movlegal( Bg, 1( m := movgen( Bg, 1(s := 9 to 56, Bg.pcs[ s] == p)),
  1128.         m[ 6] == ":")) then {
  1129.     / Blind & write( "yes.")
  1130.     Any := "Yes"
  1131.     }
  1132.     else
  1133.     / Blind & write( "no.")
  1134. end
  1135.  
  1136.  
  1137. procedure yrend( )
  1138.  
  1139. #   Process opponent's end command:
  1140.  
  1141.     write( "Game terminated by ", Yu, ".")
  1142.     kstop( "by " || Yu)
  1143. end
  1144.  
  1145.  
  1146. procedure yrmessage( )
  1147.  
  1148. #   Process opponent's message command:
  1149.  
  1150.     local    line
  1151.  
  1152.     line := read( Yrcomm) | kstop( "can't read opponent message")
  1153.     write( "Message from ", Yu, ": ", line)
  1154.     write( Logfile, line)
  1155.     write( "Please write a one-line response:")
  1156.     line := read( ) | kstop( "can't read response to opponent message")
  1157.     write( Mycomm, line)
  1158.     write( Logfile, line)
  1159. end
  1160.  
  1161.  
  1162. procedure yrtry( mt)
  1163.  
  1164. #   Process opponent move try (or other type-in!) mt:
  1165.  
  1166.     local    ml, result, s, mtr, b, po, sfr, sto
  1167.  
  1168.     if ml := movtry( mt) then {
  1169.     Lmv := ml
  1170.     write( Yu, " (", Yrcol, ") has moved.")
  1171.     write( Logfile, Yu, "'s move ", Bg.ply / 2 + 1, " is ", ml)
  1172.     / Blind & write( Yu, " captures on ", s2sn( sqrcap( Bg, ml)))
  1173.     if find( ml[ -1], "RNBQ") then
  1174.         / Blind & write( Yu, " promotes a pawn.")
  1175.     movmake( Bg, ml)
  1176.     / Blind & saycheck( )
  1177.     Any := &null
  1178.     Tries := set( )
  1179.     if result := gamend( Bg) then {
  1180.         write( "Game ends; result: ", result)
  1181.         write( Logfile, "Result: ", result)
  1182.         kstop( "end of game")
  1183.         }
  1184.     }
  1185.  
  1186. #   Inform Me if opponent move illegal but not impossible.  Don't inform
  1187. #   if illegal move already tried.  Note: distinction between "illegal"
  1188. #   and "impossible" is tricky and may not always be made properly.
  1189. #   Note: don't bother informing if in blind mode.
  1190.  
  1191.     else {
  1192.     \ Blind & fail
  1193.     mtr := map( tokens( mt)) | ""
  1194.     if mtr == "o-o" then
  1195.         mtr := (Bg.cmv == "White", "e1g1") | "e8g8"
  1196.     else if mtr == "o-o-o" then
  1197.         mtr := (Bg.cmv == "White", "e1c1") | "e8c8"
  1198.     mtr := mtr[ 1:5] | fail
  1199.     if member( Tries, mtr) then fail
  1200.     insert( Tries, mtr)
  1201.     b := copy( Bg)
  1202.     po := (b.cmv[ 1] == "W", "prnbqk") | "PRNBQK"
  1203.     b.pcs := map( b.pcs, po, "      ")
  1204.     sfr := sn2s( mtr[ 1:3]) | fail
  1205.     sto := sn2s( mtr[ 3:5]) | fail
  1206.     if sn2s( movgen( b, sfr)[ 4:6]) = sto then
  1207.         / Any & write( Yu, " tried illegal move.")
  1208.     else {
  1209.         b.pcs[ sto] := pc2p( "P", b.cnm)
  1210.         if sn2s( movgen( b, sfr)[ 4:6]) = sto then
  1211.         write( Yu, " tried illegal move.")
  1212.         }
  1213.     }
  1214. end
  1215.